/**
 * @description: SendRecordSrv
 */

import type { CommonAPI } from '../types/all'
import { defHttp } from '../http'

// ------------------------------------节点版本----------------------------------------------------------

/** 国家代码映射列表 */
export const addCdnCountryApi: CommonAPI<
  '/cdn/config/country-code',
  'get'
> = params => defHttp.get(`/cdn/config/country-code`, { params })

/** 创建节点 */
export const addCdnNodeApi: CommonAPI<'/v1/cdn/node', 'post'> = data =>
  defHttp.post(`/v1/cdn/node`, data)

/** 更新节点信息 */
export const updateCdnNodeApi: CommonAPI<'/v1/cdn/node', 'put'> = data =>
  defHttp.put(`/v1/cdn/node`, data)

/** 同步配置（节点定期拉取配置更新） */
export const addCdnNodeSyncApi: CommonAPI<
  '/v1/cdn/node/config/sync',
  'post'
> = data => defHttp.post(`/v1/cdn/node/config/sync`, data)

/** 控制节点（启动/停止/重启等操作） */
export const postCdnNodeControlApi: CommonAPI<
  '/v1/cdn/node/control',
  'post'
> = data => defHttp.post(`/v1/cdn/node/control`, data)

/** 节点注册（节点首次接入时调用） */
export const addCdnNodeRegisterApi: CommonAPI<
  '/v1/cdn/node/register',
  'post'
> = data => defHttp.post(`/v1/cdn/node/register`, data)

/** 节点详情 */
export const getNodeDetailApi: CommonAPI<'/v1/cdn/node/{id}', 'get'> = data =>
  defHttp.get(`/v1/cdn/node/${data.id}`, data)

/** 删除节点 */
export const deleteCdnNodeApi: CommonAPI<
  '/v1/cdn/node/{id}',
  'delete'
> = data => defHttp.delete(`/v1/cdn/node/${data.id}`, data)

/** 查询节点列表 */
export const getCdnNodeListApi: CommonAPI<'/v1/cdn/nodes', 'get'> = params =>
  defHttp.get(`/v1/cdn/nodes`, { params })

/** 获取集群级联视图（按集群和级别展示节点） */
export const getCdnNodeCascadeApi: CommonAPI<
  '/v1/cdn/nodes/cascade',
  'get'
> = params => defHttp.get(`/v1/cdn/nodes/cascade`, { params })

/** 批量更新节点所属集群和级联级别 */
export const updateCdnNodeCascadeApi: CommonAPI<
  '/v1/cdn/nodes/cascade_region',
  'put'
> = data => defHttp.put(`/v1/cdn/nodes/cascade_region`, data)

/** 获取简单的节点列表（仅包含基本信息） */
export const getCdnNodeSimpleApi: CommonAPI<
  '/v1/cdn/nodes/simple',
  'get'
> = params => defHttp.get(`/v1/cdn/nodes/simple`, { params })

/** 获取节点树形结构（按分组展示） */
export const getCdnNodeTreeApi: CommonAPI<
  '/v1/cdn/node-groups/node-tree',
  'get'
> = params => defHttp.get(`/v1/cdn/node-groups/node-tree`, { params })

/** 添加节点绑定 WAF */
export const updateCdnWafNodeUnbindApi: CommonAPI<
  '/v1/cdn/node/waf-node-bind',
  'post'
> = data => defHttp.post(`/v1/cdn/node/waf-node-bind`, data)

// /** 删除节点 */
// export const deleteCdnWafNodeUnbindApi: CommonAPI<
//   '/v1/cdn/node/waf/node-unbind',
//   'delete'
// > = params => defHttp.delete(`/v1/cdn/node/waf/node-unbind`, { params })

export const deleteCdnWafNodeUnbindApi: CommonAPI<
  '/v1/cdn/node/waf-node-unbind',
  'delete'
> = data => defHttp.delete(`/v1/cdn/node/waf-node-unbind`, { data })

// ------------------------------------WAF----------------------------------------------------------

/** 创建 WAF 规则 */
export const addCdnNodeWafApi: CommonAPI<'/v1/cdn/node/waf', 'post'> = data =>
  defHttp.post(`/v1/cdn/node/waf`, data)

/** 更新 WAF 规则 */
export const updateCdnNodeWafApi: CommonAPI<'/v1/cdn/node/waf', 'put'> = data =>
  defHttp.put(`/v1/cdn/node/waf`, data)

/** 更新绑定 */
export const updateCdnNodeWafBindApi: CommonAPI<
  '/v1/cdn/node/waf/bind',
  'put'
> = data => defHttp.put(`/v1/cdn/node/waf/bind`, data)

/** 查询可用条件 */
export const getCdnNodeWafConditionsApi: CommonAPI<
  '/v1/cdn/node/waf/conditions',
  'get'
> = params => defHttp.get(`/v1/cdn/node/waf/conditions`, { params })

/** 更新 WAF 规则优先级 */
export const updateCdnNodeWafPriorityApi: CommonAPI<
  '/v1/cdn/node/waf/priority',
  'put'
> = data => defHttp.put(`/v1/cdn/node/waf/priority`, data)

/** 更新 WAF 规则状态 */
export const updateCdnNodeWafStatusApi: CommonAPI<
  '/v1/cdn/node/waf/status',
  'put'
> = data => defHttp.put(`/v1/cdn/node/waf/status`, data)

/** 获取 WAF 规则详情 */
export const getCdnNodeWafIdApi: CommonAPI<
  '/v1/cdn/node/waf/{id}',
  'get'
> = data => defHttp.get(`/v1/cdn/node/waf/${data.id}`, { data })

/** 删除 WAF 规则 */
export const deleteCdnNodeWafIdApi: CommonAPI<
  '/v1/cdn/node/waf/{id}',
  'delete'
> = data => defHttp.delete(`/v1/cdn/node/waf/${data.id}`, { data })

/** 获取绑定节点ID */
export const getCdnNodeWafBindingsApi: CommonAPI<
  '/v1/cdn/node/waf/{waf_id}/bindings',
  'get'
> = data => defHttp.get(`/v1/cdn/node/waf/${data.waf_id}/bindings`, { data })

/** 查询 WAF 规则 */
export const getCdnNodeWafsApi: CommonAPI<
  '/v1/cdn/node/wafs',
  'get'
> = params => defHttp.get(`/v1/cdn/node/wafs`, { params })

// ------------------------------------安全日志----------------------------------------------------------

/** waf规则曲线 */
export const getCdnStatisticsWafApi: CommonAPI<
  '/v1/cdn/statistics/node/waf_curve',
  'post'
> = data => defHttp.post(`/v1/cdn/statistics/node/waf_curve`, data)

/** 节点日志明细 */
export const getCdnStatisticsWafLogApi: CommonAPI<
  '/v1/cdn/statistics/node/waf_log',
  'post'
> = data => defHttp.post(`/v1/cdn/statistics/node/waf_log`, data)

/** 节点waf概览 */
export const getCdnStatisticsWafOverviewApi: CommonAPI<
  '/v1/cdn/statistics/node/waf_overview',
  'post'
> = data => defHttp.post(`/v1/cdn/statistics/node/waf_overview`, data)

// ------------------------------------节点版本----------------------------------------------------------

/** 获取节点安装命令（一键安装命令） */
export const getVersionInstallCommandApi: CommonAPI<
  '/v1/cdn/node/install-command',
  'get'
> = params => defHttp.get(`/v1/cdn/node/install-command`, { params })

/** 获取指定版本的更新说明 */
export const getVersionImprintApi: CommonAPI<
  '/v1/cdn/node/version/imprint',
  'get'
> = params => defHttp.get(`/v1/cdn/node/version/imprint`, { params })

/** 获取指定版本的详细信息 */
export const getVersionInfoApi: CommonAPI<
  '/v1/cdn/node/version/info',
  'get'
> = params => defHttp.get(`/v1/cdn/node/version/info`, { params })

/** 获取指定版本的更新说明 */
export const getVersionLatestApi: CommonAPI<
  '/v1/cdn/node/version/latest',
  'get'
> = params => defHttp.get(`/v1/cdn/node/version/latest`, { params })

/** 查询节点版本列表 */
export const getVersionListApi: CommonAPI<
  '/v1/cdn/node/version/query',
  'get'
> = params => defHttp.get(`/v1/cdn/node/version/query`, { params })

/** 切换节点版本（批量升级/降级节点版本） */
export const updateVersionSwitchApi: CommonAPI<
  '/v1/cdn/node/version/switch',
  'put'
> = data => defHttp.put(`/v1/cdn/node/version/switch`, data)

/** 上传新的节点版本包 */
export const addCdnVersionUploadApi: CommonAPI<
  '/v1/cdn/node/version/upload',
  'post'
> = data => defHttp.post(`/v1/cdn/node/version/upload`, data)

/** 删除节点包 */
export const deleteCdnVersionApi: CommonAPI<
  '/v1/cdn/node/version/{id}',
  'delete'
> = data => defHttp.delete(`/v1/cdn/node/version/${data.id}`, data)

// /** 初始化分片上传 */
// export const addCdnVersionUploadInitApi: CommonAPI<'/v1/cdn/node/version/tus', 'post'> = data =>
//   defHttp.post(`/v1/cdn/node/version/tus`, data)

// /** 上传分片 */
// export const putCdnVersionUploadPartApi: CommonAPI<
//   '/v1/cdn/node/version/upload/part/binary?upload_id={upload_id}&object_key={object_key}&part_number={part_number}',
//   'put'
// > = data => defHttp.put(`/v1/cdn/node/version/upload/part/binary?upload_id=${data.upload_id}&object_key=${data.object_key}&part_number=${data.part_number}`, data)

/** 完成分片上传 */
// export const postCdnVersionUploadCompleteApi: CommonAPI<'/v1/cdn/node/version/upload/pars', 'post'> = data =>
//   defHttp.post(`/v1/cdn/node/version/upload/pars`, data)

export const postCdnVersionUploadCompleteApi: CommonAPI<
  '/v1/cdn/node/version/upload/parse',
  'get'
> = params => defHttp.get(`/v1/cdn/node/version/upload/parse`, { params })

// ------------------------------------端口配置----------------------------------------------------------

/** 查询端口 */
export const getCdnHttpApi: CommonAPI<
  '/cdn/config/http-ports',
  'get'
> = params => defHttp.get(`/cdn/config/http-ports`, { params })

/** 更新端口 */
export const updateCdnHttpApi: CommonAPI<
  '/cdn/config/http-ports',
  'put'
> = data => defHttp.put(`/cdn/config/http-ports`, data)

// ------------------------------------集群列表----------------------------------------------------------
/** 查询集群 */
export const getCdnClusterListApi: CommonAPI<
  '/v1/cdn/clusters',
  'get'
> = params => defHttp.get(`/v1/cdn/clusters`, { params })

/** 查询集群 */
// export const getCdnClusterSimpleListApi: CommonAPI<
//   '/v1/cdn/clusters/simple',
//   'get'
// > = params => defHttp.get(`/v1/cdn/clusters/simple`, { params })

/** 删除集群 */
export const deleteCdnClusterApi: CommonAPI<
  '/v1/cdn/cluster',
  'delete'
> = params => defHttp.delete(`/v1/cdn/cluster`, { params })

/** 创建集群 */
export const addCdnClusterApi: CommonAPI<'/v1/cdn/cluster', 'post'> = data =>
  defHttp.post(`/v1/cdn/cluster`, data)

/** 更新集群 */
export const updateCdnClusterApi: CommonAPI<'/v1/cdn/cluster', 'put'> = data =>
  defHttp.put(`/v1/cdn/cluster`, data)

/** 更新集群状态 */
export const updateCdnClusterStatusApi: CommonAPI<
  '/v1/cdn/cluster/status',
  'put'
> = data => defHttp.put(`/v1/cdn/cluster/status`, data)

/** 更新站点解析信息 */
export const updateCdnSiteClusterApi: CommonAPI<
  '/v1/cdn/site/cname',
  'put'
> = data => defHttp.put(`/v1/cdn/site/cname`, data)

// -----------------------------------域名管理-----------------------------------------------------------
/** 删除域名 */
export const deleteCdnDomainApi: CommonAPI<
  '/v1/cdn/resolve/domain',
  'delete'
> = params => defHttp.delete(`/v1/cdn/resolve/domain`, { params })

/** 创建域名 */
export const addCdnDomainApi: CommonAPI<
  '/v1/cdn/resolve/domain',
  'post'
> = data => defHttp.post(`/v1/cdn/resolve/domain`, data)

/** 更新域名 */
export const updateCdnDomainApi: CommonAPI<
  '/v1/cdn/resolve/domain',
  'put'
> = data => defHttp.put(`/v1/cdn/resolve/domain`, data)

/** 查询域名 */
export const getCdnDomainListApi: CommonAPI<
  '/v1/cdn/resolve/domains',
  'get'
> = params => defHttp.get(`/v1/cdn/resolve/domains`, { params })

/** 域名节点绑定 */
export const getCdnClusterNodeListApi: CommonAPI<
  '/v1/cdn/resolve/domain/node_bindings',
  'get'
> = params => defHttp.get(`/v1/cdn/resolve/domain/node_bindings`, { params })

/** 域名站点绑定 */
export const getCdnClusterSiteListApi: CommonAPI<
  '/v1/cdn/resolve/domain/site_bindings',
  'get'
> = params => defHttp.get(`/v1/cdn/resolve/domain/site_bindings`, { params })

// ------------------------------------分组列表----------------------------------------------------------

/** 查询分组 */
export const getCdnGroupListApi: CommonAPI<
  '/v1/cdn/node-groups',
  'get'
> = params => defHttp.get(`/v1/cdn/node-groups`, { params })

/** 查询分组详情 */
export const getCdnGroupApi: CommonAPI<
  '/v1/cdn/node-group/{id}',
  'get'
> = data => defHttp.get(`/v1/cdn//node-group/${data.id}`, data)

/** 删除分组 */
export const deleteCdnGroupApi: CommonAPI<
  '/v1/cdn/node-group/{id}',
  'delete'
> = data => defHttp.delete(`/v1/cdn/node-group/${data.id}`, data)

/** 创建分组 */
export const addCdnGroupApi: CommonAPI<'/v1/cdn/node-group', 'post'> = data =>
  defHttp.post(`/v1/cdn/node-group`, data)

/** 更新分组 */
export const updateCdnGroupApi: CommonAPI<'/v1/cdn/node-group', 'put'> = data =>
  defHttp.put(`/v1/cdn/node-group`, data)

/** 更新分组状态 */
export const updateCdGroupStatusApi: CommonAPI<
  '/v1/compute/machine_group/status',
  'post'
> = data => defHttp.put(`/v1/compute/machine_group/status`, data)
